﻿// -------------------------------------------------------------------------
//    @FileName         :    NFCityPlayerTeamExt.cpp
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-15
//    @Email			:    445267987@qq.com
//    @Module           :    NFCityPlayerTeamExt
//    @Desc             :
//
// -------------------------------------------------------------------------

#include "NFCityPlayerTeamExt.h"

#include "NFCityPlayerUtil.h"
#include "proto_common_team.nanopb.h"

NFCityPlayerTeamExt::NFCityPlayerTeamExt()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFCityPlayerTeamExt::~NFCityPlayerTeamExt()
{
}

int NFCityPlayerTeamExt::CreateInit()
{
    return 0;
}

int NFCityPlayerTeamExt::ResumeInit()
{
    return 0;
}

int NFCityPlayerTeamExt::InitTeamData(const proto_ff::CityTeamData* pTeamData)
{
    CHECK_NULL(0, pTeamData);
    m_stTeamData.FromPb(*pTeamData);
    return 0;
}

bool NFCityPlayerTeamExt::IsTeamFollow(uint64_t ullRoleId)
{
    auto pMember = GetTeamMember(ullRoleId);
    if (pMember && pMember->state == E_Team_Player_State_Follow)
    {
        return true;
    }
    return false;
}

bool NFCityPlayerTeamExt::IsTeamLeader(uint64_t ullRoleId)
{
    auto pMember = GetTeamMember(ullRoleId);
    if (pMember && pMember->is_leader)
    {
        return true;
    }
    return false;
}

bool NFCityPlayerTeamExt::IsInTeam(uint64_t ullRoleId)
{
    auto pMember = GetTeamMember(ullRoleId);
    if (pMember)
    {
        return true;
    }
    return false;
}

int32_t NFCityPlayerTeamExt::GetTeamMemberNum()
{
    int iNum = 0;
    for(auto iter = m_stTeamData.team_member.list_begin(); iter != m_stTeamData.team_member.list_end(); ++iter)
    {
        if (iter->second.state == E_Team_Player_State_Follow)
        {
            ++iNum;
        }
    }
    return iNum;
}

NFCityPlayer* NFCityPlayerTeamExt::GetLeader()
{
    for(auto iter = m_stTeamData.team_member.list_begin(); iter != m_stTeamData.team_member.list_end(); ++iter)
    {
        if (iter->second.is_leader)
        {
            return NFCityPlayerUtil::GetPlayerByRoleID(iter->second.role_id);
        }
    }
    return nullptr;
}

CityTeamMember* NFCityPlayerTeamExt::GetTeamMember(uint64_t ullRoleId)
{
    auto iter = m_stTeamData.team_member.find(ullRoleId);
    if (iter != m_stTeamData.team_member.end())
    {
        return &iter->second;
    }
    return nullptr;
}
